/*
 * @Author: halande
 * @Description: 处理挽留弹窗的逻辑
 */
const leaveMixin={
  methods:{
    async handleLeavePage () {
      let res= localStorage.getItem('RETAIN_COUPON_LIST') 
      if (res){
        let couponList = JSON.parse(res)
        if (couponList.length>0){
          // console.log('打开弹窗')
          this.editPage({ field:'retainPopState',value:true })
          this.editPage({ field:'retainCouponList',value:couponList })
          let popComponentId = localStorage.getItem('RETAIN_POP_COMPONENT_ID')
          this.$sendQdas('8888110507', {
            item_name: '挽留弹窗-弹出显示',
            item_id:popComponentId
          })
        } else {
          window.App.back()
        }
        
      } else {
        window.App.back()
      }  
    },
    async loadRetainPopCoupon(){
      console.log('进入loadRetainPopCoupon方法')
      if (!this.userNo){
        return
      }
      let popComponentId = localStorage.getItem('RETAIN_POP_COMPONENT_ID')
      popComponentId=popComponentId?popComponentId:'1'
      let requestData = { 
        userNo: this.userNo, 
        activityCode: this.activityCode, 
        moduleCodeLast: popComponentId,
        versionDomain:this.versionRule
      }
      let list=''
      const res=await this.$axios.post('/coupon/detainPopInfo', requestData).catch(e => {
        console.log('挽留请求接口失败！'+e.message)
      })
      if (res.flag==='S' && res.data?.couponList?.length>0){
        list = JSON.stringify(res.data.couponList)
        localStorage.setItem('RETAIN_POP_COMPONENT_ID',res.data.moduleCode)
      } 
      localStorage.setItem('RETAIN_COUPON_LIST',list ) 
    }
  }
}

export default leaveMixin